package com.platform.toutiao.bean;


import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.platform.toutiao.error.TouTiaoErrorException;

import me.chanjar.weixin.common.util.json.GsonHelper;

public class TouTiaoCode2SessionResult {
	private String sessionKey;

	private String openId;

	private String anonymousOpenId;

	public static TouTiaoCode2SessionResult fromJson(String jsonStr) throws TouTiaoErrorException {
		Gson g = new Gson();
		JsonObject jsonObject = g.fromJson(jsonStr, JsonObject.class);
		if (jsonObject.get("errcode") != null) {
			throw TouTiaoErrorException.error(jsonStr);
		}
		TouTiaoCode2SessionResult ttCode2SessionResult = new TouTiaoCode2SessionResult();
		ttCode2SessionResult.setSessionKey(GsonHelper.getString(jsonObject, "session_key"));
		ttCode2SessionResult.setOpenId(GsonHelper.getString(jsonObject, "openid"));
		ttCode2SessionResult.setAnonymousOpenId(GsonHelper.getString(jsonObject, "anonymous_openid"));
		return ttCode2SessionResult;
	}

	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getAnonymousOpenId() {
		return anonymousOpenId;
	}

	public void setAnonymousOpenId(String anonymousOpenId) {
		this.anonymousOpenId = anonymousOpenId;
	}

}
